﻿<html>
	<head>
		<title>Foglalt termények</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" href="v-a.css" type="text/css">
	</head>
	<?php	
		session_start();
		$_SESSION['sh']="";
		//print_r ($_POST);
		require_once ('dbConnect.php');
		include ('functions.php');

		if(isset($_POST['Vissza'])) {
			$_SESSION['uzenet']="";
			header('Location: index.php');
			exit;
		}
		if(isset($_POST['saját_termék_foglalások'])) {
			$_SESSION['sh']=$_SESSION['username'];
		}
		
			
			
		if(isset($_POST['visszaigazol'])) {
			$_SESSION['uzenet']="";
			$_SESSION['sh']=$_SESSION['username'];
			//$_SESSION['editedhirdetes']=$_POST['hirdetesID'][firstkey($_POST['lefoglal'])];
			//print_r($_POST['mennyiseg'][firstkey($_POST['lefoglal'])]);
			//print_r($_POST['foglalasID'][firstkey($_POST['visszaigazol'])]);
			$result=MyDatabase::getConnection()->multi_query("CALL visszaigazol('".$_POST['foglalasID'][firstkey($_POST['visszaigazol'])]."')");
			if (!$result) {
				$_SESSION['uzenet']='mysql_error: ' . MyDatabase::getConnection()->error;
				header('Location: foglalaslist.php');
			}
			else{
				$_SESSION['uzenet']='Eladás megtörtént';
				
			}
			//exit;
		}
		if(isset($_POST['torol'])) {
			$_SESSION['uzenet']="";
			//$_SESSION['editedhirdetes']=$_POST['hirdetesID'][firstkey($_POST['lefoglal'])];
			//print_r($_POST['mennyiseg'][firstkey($_POST['lefoglal'])]);
			//print_r($_POST['foglalasID'][firstkey($_POST['visszaigazol'])]);
			$result=MyDatabase::getConnection()->multi_query("CALL foglalastorol('".$_POST['foglalasID'][firstkey($_POST['torol'])]."')");
			if (!$result) {
				$_SESSION['uzenet']='mysql_error: ' . MyDatabase::getConnection()->error;
			}
			else{
				$_SESSION['uzenet']='Foglalás törölve';
				
			}
			//exit;
		}

		
		//if ((checkuser("admin")==0) and (checkuser("termelő")==0)){
			//$_SESSION['uzenet']= "access denied";
		//}
		
	?>
	
	<body>
		<table ><tr HEIGHT="10"><td WIDTH="80%">Foglalt termények</td><td WIDTH="20%"><?php include('kilepes.php');?></td></tr></table>
		
		<hr>
		
		<?php 
			printf($_SESSION['uzenet']);
		?>
		<hr>
		<form name='menu' method='post' action="foglalaslist.php">
		<table>
		<tr>
		<td>
			<input type='submit'  class='button' name='Vissza' value='<< vissza' />
		</td>
		<?php 
			//if ((checkuser("admin")==1) or (checkuser("termelő")==1))
			//echo "<td>
			//	<input type='submit'  class='button' name='új' value='új' />
			//</td>";
		?>
		</tr>
		</table>

			<?php 
			$tjog=false;
			if (checkuser("admin")==1)
				$tjog=true;
			
			if ((checkuser("admin")==1) or (checkuser("termelő")==1)){
				$query="CALL foglalaslist('".$_SESSION['sh']."');";
				if (MyDatabase::getConnection()->multi_query($query)) {
						echo "<table id='one-column-emphasis'>
						<td>ID</td><td>foglalás időpont</td><td>foglaló user</td><td>mennyiség</td><td>mértékegység</td><td>termék</td><td>termelő</td><td>egységár</td><td>fizetendő</td><td></td>";
						
						if ($result = MyDatabase::getConnection()->store_result()) {
							$j=0;
							while ($row = $result->fetch_row()) {
								echo "<tr>";
								echo "<input type=hidden name=foglalasID[$j] value=$row[0]><td>$row[0]</td>";
								//echo "<td>$row[8]</td>";
								for ($i=1;$i<9;$i++){
									echo "<td>".$row[$i]."</td>";
								}
								//echo '<td><img src="data:image/jpeg;base64,' . base64_encode( $row[7] ) . '" width="100" /></td>';
								//echo "<td><input type=text size=13 name=mennyiseg[$j] ></td>
								echo "<td><input type='submit'  class='tablazatbutton' name='visszaigazol[$j]' value='visszaigazol' /></td>";
								
								if ($tjog)
									echo "<td><input type='submit'  class='tablazatbutton' name='torol[$j]' value='töröl' /></td>";
								
								$j++;
								echo "</tr>";
							}
							$result->free();
						}
						echo "</table>";
				}
				else{
					$_SESSION['uzenet']= MyDatabase::getConnection()->error;
					//printf(MyDatabase::getConnection()->error);
				}
			}
			?>
		</form>
	</body>
</html>

